﻿using BasicModuleWebApiJWTAuthorization.DBContextx;
using BasicModuleWebApiJWTAuthorization.Module;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;

namespace BasicModuleWebApiJWTAuthorization.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class RegisterController : ControllerBase
    {
        public MysqlDBContext mysqlDBContext { get; set; }

        public RegisterController(MysqlDBContext xmysqlDBContext)
        {
            this.mysqlDBContext = xmysqlDBContext;
        }

        [HttpPost("UsetRegister")]
        public IActionResult UsetRegister(T_User t_User)
        {
            BasicModuleWebApiJWTAuthorization.Model.User user = mysqlDBContext.users.Where(x => x.Name == t_User.Name && x.Passwd == x.Passwd).FirstOrDefault();
            if (user != null)
                return Ok("用户已经注册");
            else
            {
                BasicModuleWebApiJWTAuthorization.Model.User user1 = new Model.User() { Name = t_User.Name, Passwd = t_User.Password };
                mysqlDBContext.users.Add(user1);
                mysqlDBContext.SaveChanges();
                return Ok("注册成功");
            }
        }
    }
}
